<template>
	<view>
		<u-navbar :border-bottom="false" :title="subTitle" title-color="#fff" back-icon-color="#fff"></u-navbar>
		<view  class="subList">
			<view  @click="subItemClick(item.resourceId)" class="subItem" v-for="(item,subIndex) in subItem" :key="subIndex">
				<view class="subItemLeft" :class="[item.isNew?'subActive':'']">
					<!-- <u-image width="100%" height="100%" :src="item.thumbnail"></u-image> -->
					<image :src="item.thumbnail"></image>
					<view class="subContent">
						<text>{{ item.resourceName }}</text>
					</view>
					<view class="subItemTime">{{ item.videoDurationStr}}</view>
				</view>
				<view class="subItemRight">
					<view class="subjectTit">{{item.subName}}</view>
					<view class="subjectTxt">{{item.chapterName}}</view>
					<view>
						<my-icon name="eyes" style="color:#C2C2C2;font-size:20upx;" label-size="24upx" label-color="#A6A6A6" :label="item.views.toString()"></my-icon>
						</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				subTitle:'',//名称
				subItem:'',//科目列表
				subItemId:'',//ID
			};
		},
		onLoad(options) {
		  // console.log(options.subid,'传递来的参数')
			this.getClassList(options.subid)
			this.subItemId=options.subid
			this.subTitle=options.title;
		},
		onShow(){
			this.getClassList(this.subItemId)
		},
		methods:{
			// 刷新
			handleRefresh() {
				return this.getClassList(this.subItemId)
			},
			getClassList(id){
				//课程列表
				return new Promise((resolve, reject) => {
					this.request
						.get('/app/class/getCourseChapter',{'subId':id})
						.then(res => {
							this.subItem=res;
							resolve();
						})
						.catch(reject);
				});
			},
			// 点击跳转
			subItemClick(data){
				uni.navigateTo({
					url: './subjectDetail?resourceId='+data
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.subItem{
		display: flex;
		justify-content: space-between;
		// width: 100%;
		margin: 0 30upx;
		padding: 30upx 0;
		border-bottom: 1px solid #EBEBEB;
	}
	.subContent{
		display: flex;
		justify-content: center;
		align-items: center;
		width: 100%;
		height: 100%;
		position: absolute;
		top: 0;
		left: 0;
		color: white;
		text {
			display: block;
			text-align: center;
			font-size: 32upx;
			font-weight: 600;
			overflow: hidden;
			width: 221upx;
			max-height: 80upx;
			line-height: 40upx;
			vertical-align: middle;
		}
	}
	.subItemLeft{
		position: relative;
				width: 286upx;
				height: 176upx;
		    margin-right: 29upx;
		    border-radius: 10upx;
		    overflow: hidden !important;
				image{
					border-radius: 10upx;
					width: 100%;
					height: 100%;
				}
	}
	.subItemLeft.subActive::before{
	   	content: 'new';
	   	position: absolute;
	   	top: 0;
	   	left: 0;
	   	height: 30upx;
	   	line-height: 30upx;
	   	padding: 0upx 16upx 0 10upx;
			border-radius: 10upx 0 0 0;
	   	text-align: center;
	   	background: $linear-bg;
	   	clip-path: polygon(0% 0%, 0% 100%, calc(100% - 10upx) 100%, 100% 0%);
	   	font-size: 22upx;
	   	font-weight: 400;
	   	color: #ffffff;
	   	z-index: 1;
	}
	.subItemTime{
		position: absolute;
		right: 15upx;
		top: 15upx;
		background: rgba(255,255,255,.15);
		color: #fff;
		font-size: 20upx;
		padding: 0 10upx;
		border-radius: 7upx;
	}
	.subjectTit{
		color: #363940;
		font-size: 32upx;
		line-height: 70upx;
	}
	.subjectTxt{
		color: #636874;
		font-size: 28upx;
		line-height: 35upx;
		height: 70upx;
		display: block;
		overflow: hidden;
	}
	.subItemRight{
		width: 400upx;
	}
	.content {
		width: 100%;
		height: 100%;
		position: absolute;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		top: 0;
		left: 0;
		color: white;
		text {
			display: block;
			text-align: center;
			font-size: 32upx;
			font-weight: 600;
			overflow: hidden;
			margin: 51upx auto 0;
			width: 221upx;
			max-height: 80upx;
			line-height: 40upx;
			vertical-align: middle;
		}
	}
</style>
